#include <pthread.h>
#include "TcpService.h"
#include "DaemonController.h"
#include "ServerCommon.h"

void* process(void* arg)
{
	int socket = *((int*) arg);
	DaemonController daemon(socket);
	delete (int *) arg;
	if (daemon.acceptConnection()) {
		daemon.getApp();
		daemon.getInput();
		daemon.getSched();
		daemon.getPara();
		daemon.getNodes();
		daemon.setSched();
		daemon.startTask();
		daemon.uploadResults();
		daemon.freeNodes();
		daemon.cleanMess();
	}
	return NULL;
}

int main()
{
	pthread_t thread;
	TcpService connect;
	connect.createService("0.0.0.0", USER_PORT, 100);
	int socket;
	while (1) {
		int *tmp = new int;
		socket = connect.acceptConnection();
		*tmp = socket;
		pthread_create(&thread,NULL,process,tmp);
	}
	return 0;
}
